package com.csiec.clock.bean;

import org.jetbrains.annotations.NotNull;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;


public class PositionInformation {
    private static final String[] notRequired = new String[]{"姓名", "体温", "手机号", "班级", "备注", "专业"};
    //    {id: 2, name: "体温", colour: "#e2dede"
    private int id;
    private String name;
    private final String color = "#e2dede";
    private boolean isClick = false;

    public static PositionInformation[] positionInformation;

    public static PositionInformation[] getPositionInformation() {
        if (positionInformation == null) {
            positionInformation = new PositionInformation[6];
            for (int i = 0; i < positionInformation.length; i++) {
                positionInformation[i] = new PositionInformation();
                positionInformation[i].setId(i + 1);
                positionInformation[i].setName(notRequired[i]);
            }
        }
        return positionInformation;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getColor() {
        return color;
    }

    public boolean isClick() {
        return isClick;
    }

    public void setClick(boolean click) {
        isClick = click;
    }

    @NotNull
    @Override
    public String toString() {
        if (isClick) {
            return "{" +
                    "id:" + id +
                    ", name:'" + name + '\'' +
                    ", color:'" + color + '\'' +
                    '}';
        } else {
            return "";
        }
    }

    public static String getRequired() {
        JSONArray jsonArray = new JSONArray();
        JSONObject tmpObj;
        if (positionInformation == null) {
            return "[]";
        }
        for (PositionInformation information : positionInformation) {
            if (information.isClick) {
                tmpObj = new JSONObject();
                try {
                    tmpObj.put("id", information.getId());
                    tmpObj.put("name", information.getName());
                    tmpObj.put("color", information.getColor());
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                jsonArray.put(tmpObj);
            }
        }
        return jsonArray.toString();
    }

}
